home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Video Toaster 4.0
/
Video Toaster v4.0.iso
/
arexx
/
modeler
/
coordsys.lwm
< prev
next >
Wrap
Text File
|
1993-12-13
|
6KB
|
175 lines
/* CMD: Coordinate Systems
* Polar Coordinate systems conversion utility */
/* By Arnie Cachelin © 1992, 1993 NewTek Inc. */
Pi=3.14159265358
DegreesPerRadian= 180/pi
Continue=1
libadd = addlib("LWModelerARexx.port",0)
signal on error
signal on syntax
RexxMathLib = "rexxmathlib.library"
IF POS(RexxMathLib , SHOW('Libraries')) = 0 THEN
IF ~ADDLIB(RexxMathLib , 0 , -30 , 0) THEN DO
call notify(1,"!Can't find rexxmathlib.library")
exit
end
call req_begin "Coordinate System Calculator"
TxId = req_addcontrol("Enter coordinate",'T','values into appropriate "From" row')
TxId = req_addcontrol("then click OK to",'T','fill in values for other systems. ')
FromId = req_addcontrol("Convert From",'CH','Cartesian Spherical Cylindrical')
CartId = req_addcontrol("Cartesian (X, Y, Z)",'V',0)
SphereId = req_addcontrol("Spherical (R, Theta°, Phi°)",'V',0)
CylId = req_addcontrol("Cylindrical (R, Theta°, Z)",'V',0)
call req_setval FromId,2,2
call req_setval CartId, '0 0 0',0
call req_setval CylId, '0 0 0',0
call req_setval SphereId, '0 0 0',0
do while Continue /* Keep Calculating until 'CANCEL' */
x = req_post()
if (x) then do
FromType=req_getval(FromId)
select
when FromType=1 then do
Vec=req_getval(CartId)
Vec=translate(Vec,',',' ')
interpret 'v1=Sphere_R('Vec')'
interpret 'v2=Sphere_Theta('Vec')'
interpret 'v3=Sphere_Phi('Vec')'
call req_setval SphereId, v1 v2 v3
interpret 'v1=Cyl_R('Vec')'
interpret 'v2=Cyl_Theta('Vec')'
interpret 'v3=Cyl_Z('Vec')'
call req_setval CylId, v1 v2 v3
end
when FromType=2 then do
Vec=req_getval(SphereId)
Vec=translate(Vec,',',' ')
interpret 'v1=Sphere_X('Vec')'
interpret 'v2=Sphere_Y('Vec')'
interpret 'v3=Sphere_Z('Vec')'
call req_setval CartId, v1 v2 v3
interpret 'v1=Sphere_X('Vec')'
interpret 'v2=Sphere_Y('Vec')'
interpret 'v3=Sphere_Z('Vec')'
Vec=v1','v2','v3
interpret 'v1=Cyl_R('Vec')'
interpret 'v2=Cyl_Theta('Vec')'
interpret 'v3=Cyl_Z('Vec')'
call req_setval CylId, v1 v2 v3
end
when FromType=3 then do
Vec=req_getval(CylId)
Vec=translate(Vec,',',' ')
interpret 'v1=Cyl_X('Vec')'
interpret 'v2=Cyl_Y('Vec')'
interpret 'v3=Cyl_Z('Vec')'
call req_setval CartId, v1 v2 v3
interpret 'v1=Cyl_X('Vec')'
interpret 'v2=Cyl_Y('Vec')'
interpret 'v3=Cyl_Z('Vec')'
Vec=v1','v2','v3
interpret 'v1=Sphere_R('Vec')'
interpret 'v2=Sphere_Theta('Vec')'
interpret 'v3=Sphere_Phi('Vec')'
call req_setval SphereId, v1 v2 v3
end
otherwise do
call req_end()
exit
end
end
end
else do
call req_end()
exit
end
end
call req_end()
exit
syntax:
error:
t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
call end_all
if (libadd) then call remlib("LWModelerARexx.port")
exit
/*
The following functions convert between 3D cartesian coordinates (X,Y,Z)
and either cylindrical coordinates (R,Theta,Z) or Spherical
coordinates (R,Theta,Phi). The Cylindrical coordinate conversions don't
take Z inputs, since Z is the same in both cylindical and cartesian systems.
To go between spherical and cylindrical, use cartesian... or write your own.
p.s. I lied... see Cyl_Z(), z args are ok now too.
*/
/* Return R in Cylindrical coordinate system */
Cyl_R: PROCEDURE
arg xf, yf, zf
return sqrt(xf*xf+yf*yf)
Cyl_Z: PROCEDURE
arg xf, yf, zf
return zf
/* Return Theta in Cylindrical coordinate system */
Cyl_Theta: PROCEDURE EXPOSE DegreesPerRadian Pi
arg x, y, z
if x=0 then t=sign(y)*90
else t=DegreesPerRadian*atan(y/x)
if x<0 then t=t + 180 /* atan() doesn't know which quadrant you're in */
if t<0 then t=t + 360 /* atan() returns -180 to 180, I like 0 to 360 */
return t
/* Return Cartesian X from Cylindrical coordinate system */
Cyl_X: PROCEDURE EXPOSE DegreesPerRadian
arg R, Theta, Z
return R*cos(Theta/DegreesPerRadian)
/* Return Cartesian Y from Cylindrical coordinate system */
Cyl_Y: PROCEDURE EXPOSE DegreesPerRadian
arg R, Theta, Z
return R*sin(Theta/DegreesPerRadian)
/* Return R in Spherical coordinate system */
Sphere_R: PROCEDURE
arg x, y, z
return sqrt(x*x+y*y+z*z)
/* Return Theta in Spherical coordinate system */
Sphere_Theta: PROCEDURE EXPOSE DegreesPerRadian Pi
arg x, y, z
if x=0 then t=sign(y)*90
else t=DegreesPerRadian*atan(y/x)
if x<0 then t=t + 180 /* atan() doesn't know which quadrant you're in */
if t<0 then t=t + 360 /* atan() returns -180 to 180, I like 0 to 360 */
return t
/* Return Phi in Spherical coordinate system */
Sphere_Phi: PROCEDURE EXPOSE DegreesPerRadian Pi
arg x, y, z
if z=0 then return 90
else return DegreesPerRadian*atan(sqrt(x*x+y*y)/z)
/* Return Cartesian X from Spherical coordinate system */
Sphere_X: PROCEDURE EXPOSE DegreesPerRadian
arg R, Theta, Phi
return R*sin(abs(Phi)/DegreesPerRadian)*cos(Theta/DegreesPerRadian)
/* Return Cartesian Y from Spherical coordinate system */
Sphere_Y: PROCEDURE EXPOSE DegreesPerRadian
arg R, Theta, Phi
return R*sin(abs(Phi)/DegreesPerRadian)*sin(Theta/DegreesPerRadian)
/* Return Cartesian Z from Spherical coordinate system */
Sphere_Z: PROCEDURE EXPOSE DegreesPerRadian
arg R, Theta, Phi
return sign(Phi)*R*cos(Phi/DegreesPerRadian)